package com.czh.oss.adapter.impl;

import com.czh.oss.adapter.StorageAdapter;
import com.czh.oss.entity.FileInfo;
import com.czh.oss.utils.MinIoUtil;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;
import java.util.Objects;

/**
 * Minio存储服务
 * @author caozaihui
 * @version 1.0
 * @since 2024/8/17 下午 12:00
 */

public class MinioStorageAdapter implements StorageAdapter {

    @Resource
    private MinIoUtil minIoUtil;
    @Override
    @SneakyThrows
    public void createBucket(String bucketName) {
        minIoUtil.createBucket(bucketName);
    }

    @Override
    @SneakyThrows
    public void uploadObject(MultipartFile multipartFile, String bucketName, String objectName) {
        createBucket(bucketName);
        minIoUtil.uploadObject(multipartFile.getInputStream(), bucketName, objectName);
    }

    @Override
    @SneakyThrows
    public List<String> getAllBuckets() {
        return minIoUtil.getAllBuckets();
    }

    @Override
    @SneakyThrows
    public List<FileInfo> getAllObjects(String bucketName) {
        return minIoUtil.getAllObjects(bucketName);
    }

    @Override
    @SneakyThrows
    public InputStream getObject(String bucketName, String objectName) {
        return minIoUtil.getObject(bucketName,objectName);
    }

    @Override
    @SneakyThrows
    public String getUrl(String bucketName, String objectName) {
        return minIoUtil.getFileUrl(bucketName,objectName);
    }

    @Override
    @SneakyThrows
    public void deleteBucket(String bucketName) {
        minIoUtil.deleteBucket(bucketName);
    }

    @Override
    @SneakyThrows
    public void deleteObject(String bucketName, String objectName) {
        minIoUtil.deleteObject(bucketName,objectName);
    }
}
